import { bg_image } from "./indoorConfig.js";
import {couponInfoList,} from "../api/coupon/index.js"
export default {
	data() {
		return {
			bg_image,
			list: [],
			status: 'more', //more/loading/noMore
			contentText: {
				contentdown: '查看更多',
				contentrefresh: '加载中',
				contentnomore: '没有更多'
			},
			query: {
				isEffective: 1, //是否有效 0 已过期 1 未使用
				page: 1,
				pageSize: 10
			}
		}
	},
	onLoad() {
		this.getList()
	},
	methods: {
		async fetchSomething(query){
			this.query.page = 1
			this.getList()
		},
		handleTab(val) {
			this.query = {
				isEffective: val,
				page: 1,
				pageSize: 10
			}
			this.getList()
		},
		async getList() {
			let res = await couponInfoList(this.query)
			if(!res) return this.status = 'more'
			if(this.query.page == 1) this.list = [] 
			let data = res.data || {}
			this.query.page += 1
			let list = res.data.list || []
			this.list = [...this.list, ...list]
			if (list.length === 0) {
				this.status = 'noMore'
				return false;
			}
			this.status = 'more'
		},
		clickLoadMore(e) {
			this.status = 'loading'
			this.getList()
		},
		go(url){
			if(this.query.isEffective===0){
				return false
			}
			uni.navigateTo({
				url
			})
		}
	},
}